<?php
namespace PsiFramework\Classes\Factory;

/**
 * Bibliotheque
 * Gestion de ma bibliothèque
 *
 * @author Rémi San
 * @version beta
 */


/**
 * The DatabaseFactory is used to get the correct Database instance
 *
 * @package Factories
 */
class DatabaseFactory
{

    /**
     * Static function to retrieve a new instance of
     * the database based on its name
     *
     * @param   string            $databaseName   the database name
     * @return  AbstractDatabase  $service        the wanted AbstractDatabase
     */
    public static function getDatabase(/*string*/ $databaseName)
    {
        if (isNullOrEmptyString($databaseName)) {
            throw new \Exception('No DBMS class passed in arguments !');
        }

        import($databaseName);
        $db = getClassName($databaseName);
        if (!class_exists($db)) {
            throw new \Exception('DBMS class passed in arguments doesn\'t exist!');
        }

        return new $db();
    }
}
